/**
 * @version 2007-1-6
 * @author xalinx at gmail dot com
 */
package org.nanhill.commons.pattern.flow;

import java.util.LinkedList;
import java.util.List;


/**
 * @version 2007-1-6
 * @author xalinx at gmail dot com
 * 
 */
public class DefaultFlowConfig implements FlowConfig {
	private List<String> flowLocations = new LinkedList<String>();

	private ActionFactory actionFactory;

	private EventFactory eventFactory;

	private StateFactory stateFactory;

	public void setStateFactory(StateFactory stateFactory) {
		this.stateFactory = stateFactory;
	}

	public void setEventFactory(EventFactory eventFactory) {
		this.eventFactory = eventFactory;
	}

	public void setActionFactory(ActionFactory actionFactory) {
		this.actionFactory = actionFactory;
	}

	public void addFlowLocation(String file) {
		flowLocations.add(file);
	}

	/**
	 * @throws FlowException
	 * @see org.nanhill.commons.pattern.flow.FlowConfig#buildFlowFactory()
	 */
	public FlowFactory buildFlowFactory() throws FlowException {
		XmlFlowFactory factory = new XmlFlowFactory();
		factory.setActionFactory(actionFactory);
		factory.setEventFactory(eventFactory);
		factory.setStateFactory(stateFactory);
		factory.setFlowLocations(flowLocations.toArray(new String[flowLocations
				.size()]));
		factory.buildFlow();
		return factory;
	}
}
